# To change this template, choose Tools | Templates
# and open the template in the editor.
require "rubygems"
#require "pdf/writer"
#require 'rghost'
require "prawn"
require "prawn/table"
require "prawn/Measurements"
class TestController < ApplicationController
  def index

    #SAMPLE 1
    # New document, US Letter paper, portrait orientation
    #pdf = Prawn::Document.new
    # New document, A4 paper, landscaped
    #pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
    # New document, with background
    #pdf = Prawn::Document.new(:background => "#{Prawn::BASEDIR}/data/images/pigs.jpg")
    #pdf.font "#{Prawn::BASEDIR}/data/fonts/HGRSMP.ttf"
    #pdf.text "お疲れ様です。RubyOnRails！！あらがとごさいました。"
    #send_data pdf.render, :filename => 'products.pdf', :disposition => 'inline'

    #SAMPLE 2
    #    data = [["Gregory GregoryGregory GregoryGregory GregoryGregory GregoryGregory Gregory","Brown"],["James","Healy"],["Jia","Wu"]]
    # New document, A4 paper, landscaped
    
    #    Prawn::Document.generate("bounding_boxes.pdf",:page_size => "A4", :page_layout => :landscape) do
    #      font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
    #      text "A cheer for Helvetica"
    #      send_data( render )
    #      #      pdf header margin_box.top_left do
    #      #        text "Here's My Fancy Header", :size => 25, :align => :center
    #      #        stroke_horizontal_rule
    #    end
    #    end
    #    pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
    #    pdf.font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"

        

    #create a 2 dim array with 2 col and unlimited rows
    
    #    data = Array.new(2){[]}
    #    data[0] =["Gregory Gregory Gregory  Gregory","Brown"]
    #    data[1] =["Gregory","Brown"]
    #    data[2] =["Gregory","Brown"]
    #    data[3] =["Gregory","Brown"]
    #    data[4] =["Gregory","Brown"]
    #    data[1] =["Gregory","Brown"]
    #    data[5] =["Gregory","Brown"]
    #    data[6] =["Gregory","Brown"]
    #    data[7] =["Gregory","Brown"]
    #    data[8] =["Gregory","Brown"]
    #    data[9] =["Gregory","Brown"]
    #    data[10] =["Gregory","Brown"]
    #    data[11] =["Gregory","Brown"]
    #    data[12] =["Gregory","Brown"]
    #    data[13] =["Gregory","Brown"]
    #    data[14] =["Gregory","Brown"]
    #    data[15] =["Gregory","Brown"]
    #    data[16] =["Gregory","Brown"]
    #    data[17] =["Gregory","Brown"]
    #    data[18] =["Gregory","Brown"]
    #    data[19] =["Gregory","Brown"]
    #    data[20] =["Gregory","Brown"]
    

     

    # Very close to PDF::Writer's default SimpleTable output
    #    pdf.text "A cheer for Helvetica"
    #    pdf.table(data, :headers            => ["First Name", "lastname"],
    #      :font_size          => 10,
    #      :vertical_padding   => 8,
    #      :horizontal_padding => 5,
    #      :position           => :left,
    #      :row_colors         => :pdf_writer)

    #    pdf.table(data, :headers            => ["First Name", "lastname"],
    #      :font_size          => 10,
    #      :vertical_padding   => 8,
    #      :horizontal_padding => 5,
    #      :position           => :left,
    #      :row_colors         => :pdf_writer)


  end
  #def index
  #PDF::Writer::FONT_PATH = "C:\\WINDOWS\\Fonts "
  #pdf = PDF::Writer.new
  #pdf.select_font "Times-Roman"
  #pdf.text "Sample PDF Document", :font_size => 32, :justification => :center

  #respond_to do |format|
  #format.html
  #format.pdf do
  #send_data pdf.render, :filename => 'products.pdf', :disposition => 'inline'
  #end
  #end
  #end

  #def index
  #RGhost::Config::GS[:path]= 'C:\\Program Files\\gs\\gs8.64\\bin\\gswin32c.exe'
  #RGhost::Config::GS[:charset_convert]=lambda {|text| Iconv::iconv('latin1','utf8',text)}

  #doc=RGhost::Document.new
  #doc.show 'あ' , :color => :blue
  #RGhost::Config.is_ok?.render :pdf, :filename => "mytest.pdf"
  #end

  def data
    data = Array.new()
    arr = ["This is a long text to test the column width ","Brown"]
    20.times do
      data << arr
    end
    pdf = Prawn::Document.new do
      #      font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
      text "*********RubyOnRails**********"
      table data, :border_style => :grid,
        :headers => ['Column 1', 'Column 2'],
        :align_headers => { 0 => :right, 1 => :left},
        :header_text_color => 'ff0000',
        :header_color => '0000ff',
        :font_size => 12,
        :width => 350,
        :border_width => 0.5,
        :position => :center,
        :column_widths => { 0 => 100 } # 1 => 150 is omitted to keep it flexible to occupy full table width
    end
    send_data pdf.render, :filename => 'bounding_boxes.pdf', :disposition => 'inline'
  end
end
